home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 June / SGI Freeware 1998 June.iso / dist / fw_ATxgopher.idb / usr / freeware / src / xgopher.1.3 / cso.c.z / cso.c
C/C++ Source or Header  |  1998-01-21  |  20KB  |  903 lines

  1. /* cso.c
  2.    processing for CSO name server support */
  3.  
  4.      /*---------------------------------------------------------------*/
  5.      /* Xgopher        version 1.3     08 April 1993                  */
  6.      /*                version 1.2     20 November 1992               */
  7.      /*                version 1.1     20 April 1992                  */
  8.      /*                version 1.0     04 March 1992                  */
  9.      /* X window system client for the University of Minnesota        */
  10.      /*                                Internet Gopher System.        */
  11.      /* Allan Tuchman, University of Illinois at Urbana-Champaign     */
  12.      /*                Computing and Communications Services Office   */
  13.      /* Copyright 1992, 1993 by                                       */
  14.      /*           the Board of Trustees of the University of Illinois */
  15.      /* Permission is granted to freely copy and redistribute this    */
  16.      /* software with the copyright notice intact.                    */
  17.      /*---------------------------------------------------------------*/
  18.  
  19. /* Some of the "look and feel" of this panel has been influenced
  20.    by xph, an X window system interface for ph.  xph was developed by
  21.    Bradley C. Spatz, University of Florida, bcs@ufl.edu.
  22.    xph goes beyond the capabilities presented here by providing the
  23.    editing functions for changing attributes.  As gopher is an
  24.    information server, it is prudent to keep the name server
  25.    interface as simple as possible. */
  26.  
  27. #include <stdio.h>
  28.  
  29. #include <X11/Intrinsic.h>
  30. #include <X11/StringDefs.h>
  31.  
  32. #include <X11/Shell.h>
  33. #include <X11/Xaw/Command.h>
  34. #include <X11/Xaw/Form.h>
  35. #include <X11/Xaw/Label.h>
  36. #include <X11/Xaw/AsciiText.h>
  37. #include <X11/Xaw/SimpleMenu.h>
  38. #include <X11/Xaw/MenuButton.h>
  39. #include <X11/Xaw/SmeBSB.h>
  40.  
  41. #include "osdep.h"
  42. #include "cso.h"
  43. #include "help.h"
  44. #include "gui.h"
  45. #include "appres.h"
  46. #include "compatR4.h"
  47. #include "xglobals.h"
  48.  
  49. #define CSO_SHELL_TITLE    "CSO Name Server"
  50.  
  51. static void    textAppend();
  52.  
  53.  
  54. static    Widget        topLevel;
  55. static    Widget        csoShell,
  56.             doQueryButton, queryText, csoText,
  57.             nameServerLabel;
  58. static    Boolean        csoPanelCreated = False;
  59. static    Boolean        panelActive = False;
  60. static    int        nsFile = -1;
  61. static    int        endOfText = 0;
  62.  
  63.  
  64. #define THIS_POPUP_NAME        "csoPopup"
  65.  
  66.                 /* default values */
  67. static popupPosResources    placement = {
  68.  
  69.     /* position at the top of the main panel, 2/3 of the way across */
  70.     from_main, 66, 0, justify_top_left, justify_top_left, True, True
  71.     };
  72.  
  73.  
  74.  
  75.  
  76. /* ph interface routines */
  77.  
  78. #define    DELIM        ':'
  79. #define PH_TOKEN_LEN    256
  80. #define DASHES        " -------------------------------------------------\n"
  81. #define PH_BUFFSIZE    256
  82. static    char    phCommand[PH_BUFFSIZE];
  83. static    char    phResponse[PH_BUFFSIZE];
  84.  
  85. /* these macros are used for every read from the ph name server.  The
  86.    result buffer is global, so it is hard coded. */
  87.  
  88. #define RD_RESP(s) \
  89.         {int n; \
  90.         if ((n = readDelim(s, phResponse, PH_BUFFSIZE-1, DELIM)) <= 0)\
  91.                 { ph_readError(n); return False; } }
  92.         
  93.  
  94. #define RD_LINE(s) \
  95.         {int n; \
  96.         if ((n = readLine(s, phResponse, PH_BUFFSIZE-1)) <= 0)\
  97.                 { ph_readError(n); return False; } }
  98.  
  99. static    char    mailDomain[PH_TOKEN_LEN];
  100.  
  101.  
  102. /* ph_readError
  103.    error reading response from ph */
  104.  
  105. static void
  106. ph_readError(n)
  107. int    n;
  108. {
  109.     if (n == 0)
  110.         showError("End of file from Name Server!");
  111.     else
  112.         showError("Read error from Name Server!");
  113.     
  114.     return;
  115. }
  116.  
  117.  
  118. /* ph_id
  119.    send id command to ph */
  120.  
  121. static Boolean
  122. ph_id(s) 
  123. int    s;
  124. {
  125.     int    n, rc;
  126.  
  127.     sprintf(phCommand, "id %d\n", getuid());
  128.     write(s, phCommand, strlen(phCommand));
  129.  
  130.     do {
  131.         RD_RESP(s);
  132.         rc = atoi(phResponse);
  133.         RD_LINE(s);
  134.     } while (rc < 200);
  135.  
  136.     return True;
  137. }
  138.  
  139.  
  140. /* ph_quit
  141.    send quit command to ph */
  142.  
  143. static Boolean
  144. ph_quit(s) 
  145. int    s;
  146. {
  147.     int    n, rc;
  148.  
  149.     sprintf(phCommand, "quit\n");
  150.     write(s, phCommand, strlen(phCommand));
  151.  
  152.     do {
  153.         RD_RESP(s);
  154.         rc = atoi(phResponse);
  155.         RD_LINE(s);
  156.     } while (rc < 200);
  157.  
  158.     return True;
  159. }
  160.  
  161.  
  162. /* ph_siteinfo
  163.    send siteinfo command to ph */
  164.  
  165. static Boolean
  166. ph_siteinfo(s, mail) 
  167. int    s;
  168. char    *mail;
  169. {
  170.     int    n, rc;
  171.  
  172.     *mail= '\0';
  173.     sprintf(phCommand, "siteinfo\n");
  174.     write(s, phCommand, strlen(phCommand));
  175.  
  176.     do {
  177.         RD_RESP(s);
  178.         if ((rc = atoi(phResponse)) >= 200) {
  179.             RD_LINE(s);
  180.             break;
  181.         }
  182.  
  183.         /* read entry index */
  184.  
  185.         RD_RESP(s);
  186.  
  187.         /* read field name */
  188.  
  189.         RD_RESP(s);
  190.         if (strcmp(phResponse, "maildomain") == 0) {
  191.             RD_RESP(s);
  192.             strncpy(mail, phResponse, PH_TOKEN_LEN);
  193.         } else {
  194.             RD_LINE(s);
  195.         }
  196.     } while (rc < 200);
  197.  
  198.     return True;
  199. }
  200.  
  201.  
  202. /* ph_query
  203.    send query command to ph */
  204.  
  205. static Boolean
  206. ph_query(s, string) 
  207. int    s;
  208. char    *string;
  209. {
  210.     int    rc, n, entry, lastEntry=1;
  211.     Boolean    lastLine;
  212.     
  213.     sprintf (phCommand, "ph %s\n", string);
  214.     write(s, phCommand, strlen(phCommand));
  215.  
  216.     lastLine = False;
  217.     do {
  218.         RD_RESP(s);
  219.         if ((rc = atoi(phResponse)) >= 200) {
  220.             lastLine = True;
  221.             RD_LINE(s);
  222.             textAppend (phResponse);
  223.             break;
  224.         }
  225.         rc = abs(rc);
  226.         if (rc/100 != 2) {
  227.             RD_LINE(s);
  228.                 textAppend (phResponse);
  229.             continue;
  230.         }
  231.  
  232.         /* read entry index */
  233.  
  234.         RD_RESP(s);
  235.         entry = atoi(phResponse);
  236.         if (entry != lastEntry) {
  237.             textAppend (DASHES);
  238.             lastEntry = entry;
  239.         }
  240.  
  241.         /* report remainder of line */
  242.  
  243.         RD_LINE(s);
  244.             textAppend (phResponse);
  245.     } while (! lastLine);
  246.  
  247.     return True;
  248.  
  249. }
  250.  
  251.  
  252. /* matchToken
  253.    see if a token is contained in a string of tokens.  Tokens are
  254.    delimited by white space (spaces, tabs, newline). */
  255.  
  256. static Boolean
  257. matchToken(s, token)
  258. char    *s, *token;
  259. {
  260.     char    *p = s;
  261.     int    tokenLen = strlen(token);
  262.     char    *last = s + (strlen(s) - tokenLen);
  263.  
  264.     while (p < last) {
  265.         while ((*p == ' '  ||  *p == '\t'  ||  *p == '\n')  &&
  266.                                 p < last) p++;
  267.         if (strncmp(p, token, tokenLen) == 0) {
  268.             p += tokenLen;
  269.             if (*p == ' '  ||  *p == '\t'  ||  *p == '\n')
  270.                                 return True;
  271.         }
  272.         while ((*p != ' '  &&  *p != '\t'  &&  *p != '\n')  &&
  273.                                 p < last) p++;
  274.     }
  275.     return False;
  276. }
  277.  
  278.  
  279. /* ph_fields
  280.    send fields command to ph */
  281.  
  282. static Boolean
  283. ph_fields(s, string) 
  284. int    s;
  285. char    *string;
  286. {
  287.     int    rc, n, entry, lastEntry = -1;
  288.     Boolean    lastLine, descriptionLine, use;
  289.     char    fieldName[PH_TOKEN_LEN];
  290.     
  291.     sprintf (phCommand, "fields\n");
  292.     write(s, phCommand, strlen(phCommand));
  293.  
  294.     sprintf (phResponse, " ----- %s fields -----\n", string);
  295.     textAppend (phResponse);
  296.  
  297.     lastLine = False;
  298.     do {
  299.         RD_RESP(s);
  300.         if ((rc = atoi(phResponse)) >= 200) {
  301.             lastLine = True;
  302.             RD_LINE(s);
  303.             textAppend (phResponse);
  304.             break;
  305.         }
  306.         rc = abs(rc);
  307.         if (rc/100 != 2) {
  308.             RD_LINE(s);
  309.                 textAppend (phResponse);
  310.             continue;
  311.         }
  312.  
  313.         /* read entry index */
  314.  
  315.         RD_RESP(s);
  316.         entry = atoi(phResponse);
  317.         if (entry != lastEntry) {
  318.             lastEntry = entry;
  319.             descriptionLine = False;
  320.             use = False;
  321.         } else
  322.             descriptionLine = True;
  323.  
  324.         /* read field name */
  325.  
  326.         RD_RESP(s);
  327.         strcpy(fieldName, phResponse);
  328.  
  329.  
  330.         if (descriptionLine) {
  331.             RD_LINE(s);
  332.             if (use) {
  333.                 sprintf (phCommand, "%s:\t %s",
  334.                             fieldName, phResponse);
  335.                 textAppend (phCommand);
  336.             } else ;
  337.  
  338.         } else {
  339.             /* scan remainder of line for desired value */
  340.  
  341.             RD_LINE(s);
  342.  
  343.             /* loop through tokens */
  344.  
  345.             if (matchToken(phResponse, string)) use = True;
  346.         }
  347.     } while (! lastLine);
  348.  
  349.     return True;
  350. }
  351.  
  352.  
  353. /* X interface routines */
  354.  
  355.  
  356. /* shutdownNameServer
  357.    remove the panel from the display and reset the file indicators */
  358.  
  359. shutdownNameServer()
  360. {
  361.     Cardinal    n;
  362.     Arg        args[3];
  363.  
  364.     XtPopdown(csoShell);
  365.  
  366. #ifndef TEST_CSO
  367.     close(nsFile);
  368. #endif  /* TEST_CSO */
  369.     nsFile = -1;
  370.     panelActive = False;
  371.  
  372.     n=0;
  373.     XtSetArg(args[n], XtNlabel, "");  n++;
  374.     XtSetValues(nameServerLabel, args, n);
  375. }
  376.  
  377.  
  378. /* doneProc
  379.    finish a cso name server session */
  380.  
  381. static void
  382. doneProc(w, clientData, callData)
  383. Widget        w;
  384. XtPointer    clientData, callData;
  385. {
  386. #ifndef TEST_CSO
  387.     ph_quit(nsFile);
  388. #endif  /* TEST_CSO */
  389.  
  390.     shutdownNameServer();
  391. }
  392.  
  393.  
  394. /* fieldsProc
  395.    list fields with some specification */
  396.  
  397. static void
  398. fieldsProc(w, clientData, callData)
  399. Widget        w;
  400. XtPointer    clientData, callData;
  401. {
  402.     Cardinal    n;
  403.     Arg        args[3];
  404.     char        *fieldName = (char *) clientData;
  405.  
  406.     /* Lookup,  Indexed, Public, Default */ 
  407.  
  408.     if (! ph_fields(nsFile, fieldName) ) shutdownNameServer();
  409. }
  410.  
  411.  
  412. /* helpProc
  413.    provide help for a cso name server session */
  414.  
  415. static void
  416. helpProc(w, clientData, callData)
  417. Widget        w;
  418. XtPointer    clientData, callData;
  419. {
  420.         showHelp("cso help");
  421. }
  422.  
  423.  
  424. /* doQueryProc
  425.    submit a query to a cso name server */
  426.  
  427. static void
  428. doQueryProc(w, clientData, callData)
  429. Widget        w;
  430. XtPointer    clientData, callData;
  431. {
  432.     Cardinal    n;
  433.     Arg        args[3];
  434.     char        *string;
  435.  
  436.     n=0;
  437.     XtSetArg(args[n], XtNstring, &string);  n++;
  438.     XtGetValues(queryText, args, n);
  439.  
  440.     if (strlen(string) == 0) {
  441.         showError("First enter a name, then do the query.");
  442.     } else {
  443.         if (! ph_query(nsFile, string) ) shutdownNameServer();
  444.     }
  445.  
  446. }
  447.  
  448.  
  449. /* QueryOk
  450.    accept the "do query" action from a keyboard <cr> instead of the
  451.    "do query" button.  The <cr> translation is defined elsewhere.
  452.    Capitalized name is for X action proc convention. */
  453.  
  454. static void
  455. QueryOk(w, event, parms, nparms)
  456. Widget          w;
  457. XEvent          *event;
  458. String          *parms;
  459. Cardinal        *nparms;
  460. {
  461.     XtCallActionProc(doQueryButton, "set", NULL, NULL, 0);
  462.     WaitForAllPendingEventsAndExpose(
  463.             XtDisplay(csoShell),
  464.             (Window) NULL);
  465.  
  466.         doQueryProc(w, NULL, NULL);
  467.     XtCallActionProc(doQueryButton, "unset", NULL, NULL, 0);
  468.         return;
  469. }
  470.  
  471.  
  472. /* CsoDone
  473.    accept the "csodone" action from an action instead of the
  474.    "done" button.  The action translation is defined elsewhere.
  475.    Capitalized name is for X action proc convention. */
  476.  
  477. static void
  478. CsoDone(w, event, parms, nparms)
  479. Widget          w;
  480. XEvent          *event;
  481. String          *parms;
  482. Cardinal        *nparms;
  483. {
  484.     if (panelActive)
  485.         doneProc(w, NULL, NULL);
  486.  
  487.         return;
  488. }
  489.  
  490.  
  491. /* removeCsoPanel
  492.    allow external force to issue the "done" instruction to the CSO panel */
  493.  
  494. void
  495. removeCsoPanel()
  496. {
  497.     if (panelActive)
  498.         doneProc(NULL, NULL, NULL);
  499.  
  500.     return;
  501. }
  502.  
  503.  
  504. /* clearQueryProc
  505.    clear the name query text */
  506.  
  507. static void
  508. clearQueryProc(w, clientData, callData)
  509. Widget        w;
  510. XtPointer    clientData, callData;
  511. {
  512.     Cardinal    n;
  513.     Arg        args[3];
  514.  
  515.     n=0;
  516.     XtSetArg(args[n], XtNstring, "");  n++;
  517.     XtSetValues(queryText, args, n);
  518. }
  519.  
  520.  
  521. /* clearTextProc
  522.    clear the text result window */
  523.  
  524. static void
  525. clearTextProc(w, clientData, callData)
  526. Widget        w;
  527. XtPointer    clientData, callData;
  528. {
  529.     Cardinal    n;
  530.     Arg        args[3];
  531.  
  532.     n=0;
  533.     XtSetArg(args[n], XtNeditType, XawtextEdit);  n++;
  534.     XtSetValues(csoText, args, n);
  535.  
  536.     n=0;
  537.     XtSetArg(args[n], XtNstring, "");  n++;
  538.     XtSetValues(csoText, args, n);
  539.  
  540.     n=0;
  541.     XtSetArg(args[n], XtNeditType, XawtextRead);  n++;
  542.     XtSetValues(csoText, args, n);
  543.  
  544.     endOfText = 0;
  545. }
  546.  
  547.  
  548. /* textAppend
  549.    append a string to the text result window */
  550.  
  551. static void
  552. textAppend(string)
  553. char    *string;
  554. {
  555.     Cardinal    n;
  556.     Arg        args[3];
  557.     XawTextBlock    textBlock;
  558.     int        length;
  559.  
  560.     textBlock.firstPos = 0;
  561.     textBlock.length   = strlen(string);
  562.     textBlock.ptr      = string;
  563.     textBlock.format   = FMT8BIT;
  564.  
  565.     n=0;
  566.     XtSetArg(args[n], XtNeditType, XawtextAppend);  n++;
  567.     XtSetValues(csoText, args, n);
  568.  
  569.     XawTextReplace(csoText, endOfText, endOfText, &textBlock);  n++;
  570.     endOfText += textBlock.length;
  571.  
  572.     n=0;
  573.     XtSetArg(args[n], XtNeditType, XawtextRead);  n++;
  574.     XtSetValues(csoText, args, n);
  575. }
  576.  
  577.  
  578. /* displayCsoPanel
  579.    display the panel for cso name server queries */
  580.  
  581. Boolean
  582. displayCsoPanel(title, s)
  583. char        *title;
  584. int        s;
  585. {
  586.     Arg        args[10];
  587.     Cardinal    n;
  588.     Dimension    wt, wc;
  589.     Position    relX, xc, yc;
  590.     static char     geom[16];
  591.  
  592.  
  593.     n=0;
  594.     XtSetArg(args[n], XtNlabel, title);  n++;
  595.     XtSetValues(nameServerLabel, args, n);
  596.  
  597.     if (panelActive) {
  598.         clearQueryProc(NULL, NULL, NULL);
  599.         close(nsFile);
  600.  
  601.     } else {
  602.  
  603.         panelActive = True;
  604.  
  605.         positionAPopup(csoShell, topLevel, &placement);
  606.  
  607.         XtPopup (csoShell, XtGrabNone);
  608.     }
  609.  
  610.     nsFile = s;
  611. #ifndef TEST_CSO
  612.     if (! ph_id(nsFile) ) {
  613.         shutdownNameServer();
  614.         return False;
  615.     }
  616.  
  617.     if (! ph_siteinfo(nsFile, mailDomain) ) {
  618.         shutdownNameServer();
  619.         return False;
  620.     }
  621. #endif /* TEST_CSO */
  622.  
  623.         if (appResources->warpCursor) {
  624.         Position    X, Y;
  625.  
  626.         findPopupPosition(csoShell, topLevel, &placement, &X, &Y);
  627.                 XWarpPointer(XtDisplay(csoShell), None,
  628.                                 RootWindowOfScreen(XtScreen(csoShell)),
  629.                                 0, 0, 0, 0,
  630.                                 X+25, Y+100);
  631.  
  632.         }
  633.  
  634.     return True;
  635. }
  636.  
  637.  
  638. #define N_FIELDS 4
  639. static char *fieldsLabel[] = {"Default", "Lookup", "Indexed", "Public"};
  640.  
  641. /* makeCsoPanel
  642.    create the X panel for CSO name server queries */
  643.  
  644. void
  645. makeCsoPanel(top)
  646. Widget    top;
  647. {
  648.     Arg        args[10];
  649.     Cardinal    n;
  650.     int        i;
  651.     Widget        csoForm;
  652.     Widget        doneButton, helpButton,
  653.             clearQueryButton, clearTextButton,
  654.             fieldsMenuHolder, fieldsButton,
  655.             fieldsMenuItem[N_FIELDS],
  656.             queryLabel;
  657.     Dimension    nameWidth, resultWidth;
  658.     static XtActionsRec     csoActionsTable[] = {
  659.                     { "queryok", (XtActionProc) QueryOk },
  660.                     { "csodone", (XtActionProc) CsoDone }
  661.                     };
  662.  
  663.  
  664.     if (csoPanelCreated) return;
  665.  
  666.     topLevel = top;
  667.  
  668.  
  669.     /* create CSO NAME SERVER shell */
  670.  
  671.         n=0;
  672.         XtSetArg(args[n], XtNtitle, CSO_SHELL_TITLE);  n++;
  673.     csoShell = XtCreatePopupShell("csoShell",
  674.                 topLevelShellWidgetClass,
  675.                 topLevel, args, n);
  676.  
  677.  
  678.     /* create CSO NAME SERVER main panel form */
  679.  
  680.         n=0;
  681.     csoForm  = XtCreateManagedWidget("csoForm",
  682.                 formWidgetClass,
  683.                 csoShell, args, n);
  684.     
  685.  
  686.     /* create NAME SERVER label */
  687.  
  688.         n=0;
  689.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  690.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  691.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  692.         XtSetArg(args[n], XtNright,    XawChainRight);  n++;
  693.     nameServerLabel = XtCreateManagedWidget("nameServer",
  694.                 labelWidgetClass,
  695.                 csoForm, args, n);
  696.  
  697.  
  698.     /* create DONE button */
  699.  
  700.         n=0;
  701.         XtSetArg(args[n], XtNfromVert,    nameServerLabel);  n++;
  702.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  703.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  704.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  705.         XtSetArg(args[n], XtNright,    XawChainLeft);  n++;
  706.     doneButton = XtCreateManagedWidget("csoDone", commandWidgetClass,
  707.                 csoForm, args, n);
  708.         XtAddCallback(doneButton, XtNcallback, doneProc, NULL);
  709.         XtAddCallback(doneButton, XtNcallback, clearQueryProc, NULL);
  710.         XtAddCallback(doneButton, XtNcallback, clearTextProc, NULL);
  711.  
  712.  
  713.     /* create FIELDS MENU holder */
  714.  
  715.         n=0;
  716.     fieldsMenuHolder = XtCreateManagedWidget("csoFieldsMenu",
  717.                 simpleMenuWidgetClass,
  718.                 csoForm, args, n);
  719.  
  720.  
  721.     /* create FIELDS MENU ENTRIES */
  722.  
  723.     for (i=0; i<N_FIELDS; i++) {
  724.             n=0;
  725.             XtSetArg(args[n], XtNlabel, fieldsLabel[i]);  n++;
  726.         fieldsMenuItem[i] = XtCreateManagedWidget(fieldsLabel[i],
  727.                     smeBSBObjectClass,
  728.                     fieldsMenuHolder, args, n);
  729.             XtAddCallback(fieldsMenuItem[i], XtNcallback,
  730.                     fieldsProc, fieldsLabel[i]);
  731.     }
  732.  
  733.  
  734.     /* create FIELDS button */
  735.  
  736.         n=0;
  737.         XtSetArg(args[n], XtNmenuName, "csoFieldsMenu");  n++;
  738. #ifndef XGOPHER_X11R4
  739.                 XtSetArg(args[n], XtNleftBitmap, pulldownPixmap);  n++;
  740. #endif /* XGOPHER_X11R4 */
  741.         XtSetArg(args[n], XtNfromVert,    nameServerLabel);  n++;
  742.         XtSetArg(args[n], XtNfromHoriz,    doneButton);  n++;
  743.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  744.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  745.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  746.         XtSetArg(args[n], XtNright,    XawChainLeft);  n++;
  747.     fieldsButton = XtCreateManagedWidget("csoFields",
  748.                 menuButtonWidgetClass,
  749.                 csoForm, args, n);
  750.  
  751.  
  752.     /* create HELP button */
  753.  
  754.         n=0;
  755.         XtSetArg(args[n], XtNfromVert,    nameServerLabel);  n++;
  756.         XtSetArg(args[n], XtNfromHoriz,    fieldsButton);  n++;
  757.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  758.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  759.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  760.         XtSetArg(args[n], XtNright,    XawChainLeft);  n++;
  761.     helpButton = XtCreateManagedWidget("csoHelp", commandWidgetClass,
  762.                 csoForm, args, n);
  763.         XtAddCallback(helpButton, XtNcallback, helpProc, NULL);
  764.  
  765.  
  766.     /* create NAME label */
  767.  
  768.         n=0;
  769.         XtSetArg(args[n], XtNfromVert,    doneButton);  n++;
  770.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  771.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  772.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  773.         XtSetArg(args[n], XtNright,    XawChainRight);  n++;
  774.     queryLabel = XtCreateManagedWidget("csoQueryLabel",
  775.                 labelWidgetClass,
  776.                 csoForm, args, n);
  777.  
  778.  
  779.     /* create NAME TEXT entry */
  780.  
  781.         n=0;
  782.         XtSetArg(args[n], XtNeditType, XawtextEdit);  n++;
  783.         XtSetArg(args[n], XtNstring, "");  n++;
  784.         XtSetArg(args[n], XtNfromVert,    queryLabel);  n++;
  785.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  786.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  787.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  788.         XtSetArg(args[n], XtNright,    XawChainRight);  n++;
  789.     queryText = XtCreateManagedWidget("csoQueryText",
  790.                 asciiTextWidgetClass,
  791.                 csoForm, args, n);
  792.         setTextWidgetSize(queryText, 60, 1);
  793.  
  794.         n=0;
  795.         XtSetArg(args[n], XtNwidth, &nameWidth);  n++;
  796.         XtGetValues(queryText, args, n);
  797.     XtOverrideTranslations(queryText, oneLineParsed);
  798.     
  799.  
  800.     /* create DO QUERY button */
  801.  
  802.         n=0;
  803.         XtSetArg(args[n], XtNfromVert,    queryText);  n++;
  804.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  805.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  806.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  807.         XtSetArg(args[n], XtNright,    XawChainLeft);  n++;
  808.     doQueryButton = XtCreateManagedWidget("csoDoQuery", commandWidgetClass,
  809.                 csoForm, args, n);
  810.         XtAddCallback(doQueryButton, XtNcallback,
  811.                 doQueryProc, NULL);
  812.  
  813.  
  814.     /* create CLEAR QUERY button */
  815.  
  816.         n=0;
  817.         XtSetArg(args[n], XtNfromVert,    queryText);  n++;
  818.         XtSetArg(args[n], XtNfromHoriz,    doQueryButton);  n++;
  819.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  820.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  821.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  822.         XtSetArg(args[n], XtNright,    XawChainLeft);  n++;
  823.     clearQueryButton = XtCreateManagedWidget("csoClearQuery",
  824.                 commandWidgetClass,
  825.                 csoForm, args, n);
  826.         XtAddCallback(clearQueryButton, XtNcallback,
  827.                 clearQueryProc, NULL);
  828.  
  829.  
  830.     /* create CLEAR TEXT button */
  831.  
  832.         n=0;
  833.         XtSetArg(args[n], XtNfromVert,    queryText);  n++;
  834.         XtSetArg(args[n], XtNfromHoriz,    clearQueryButton);  n++;
  835.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  836.         XtSetArg(args[n], XtNbottom,    XawChainTop);  n++;
  837.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  838.         XtSetArg(args[n], XtNright,    XawChainLeft);  n++;
  839.     clearTextButton = XtCreateManagedWidget("csoClearText",
  840.                 commandWidgetClass,
  841.                 csoForm, args, n);
  842.         XtAddCallback(clearTextButton, XtNcallback,
  843.                 clearTextProc, NULL);
  844.  
  845.  
  846.     /* create TEXT display */
  847.  
  848.         n=0;
  849.         XtSetArg(args[n], XtNeditType, XawtextRead);  n++;
  850.         XtSetArg(args[n], XtNstring, "");  n++;
  851.         XtSetArg(args[n], XtNfromVert,    doQueryButton);  n++;
  852.         XtSetArg(args[n], XtNtop,    XawChainTop);  n++;
  853.         XtSetArg(args[n], XtNbottom,    XawChainBottom);  n++;
  854.         XtSetArg(args[n], XtNleft,    XawChainLeft);  n++;
  855.         XtSetArg(args[n], XtNright,    XawChainRight);  n++;
  856.     csoText = XtCreateManagedWidget("csoText", asciiTextWidgetClass,
  857.                 csoForm, args, n);
  858.         setTextWidgetSize(csoText, 60, 20);
  859.  
  860.         n=0;
  861.         XtSetArg(args[n], XtNwidth, &resultWidth);  n++;
  862.         XtGetValues(csoText, args, n);
  863.  
  864.     if (nameWidth < resultWidth) {
  865.         n=0;
  866.         XtSetArg(args[n], XtNwidth, resultWidth);  n++;
  867.         XtSetValues(queryText, args, n);
  868.     } else {
  869.         n=0;
  870.         XtSetArg(args[n], XtNwidth, nameWidth);  n++;
  871.         XtSetValues(csoText, args, n);
  872.     }
  873.  
  874.     XtAppAddActions(appcon, csoActionsTable, XtNumber(csoActionsTable));
  875.  
  876.     XtSetKeyboardFocus(csoForm, queryText);
  877.  
  878.  
  879.     /* find the popup placement for this shell */
  880.  
  881.     {
  882.     popupPosResources *resourcePlacement;
  883.  
  884.     resourcePlacement = getPopupPosResources(
  885.                 THIS_POPUP_NAME, POPUP_POS_CLASS, &placement);
  886.     bcopy( (char *) resourcePlacement, (char *) &placement,
  887.                 sizeof(popupPosResources) );
  888.     }
  889.  
  890.     setPopupGeometry(csoShell, &placement);
  891.  
  892.  
  893.         /* for ICCCM window manager protocol complience */
  894.  
  895.         XtOverrideTranslations (csoShell,
  896.             XtParseTranslationTable ("<Message>WM_PROTOCOLS: csodone()"));
  897.         XtRealizeWidget(csoShell);
  898.         (void) XSetWMProtocols (XtDisplay(csoShell), XtWindow(csoShell),
  899.                                     &wmDeleteAtom, 1);
  900.  
  901.     csoPanelCreated = True;
  902. }
  903.